<?php

require_once('../model/m_shift_change_request.php');

class shift_changes {
	
	public $requestsData = array();
	public $schedulesData = array();
	public $scheduleStatsData = array();
	public $currentDate;
	
	public function actionView(){
		include_once("../views/v_session.php");
		include_once("../views/v_header_principal_shift_changesl_ajax.html");
		include_once("../views/v_shift-changes.html");
		include_once("../views/v_footer_principal.html");
	}

	public function actionViewPendingRequests(){
		$this->requestsData = getPendingRequests(); //Get list of pending requests	
		include_once("../views/_v_shift_changes_pending.html");
	}	
	
	public function actionViewDaySchedule($date){
		
		$today = new DateTime('NOW');
		$today->setTimeZone(new DateTimeZone("America/Costa_Rica"));
		$dateArray = explode('-', $date);
		$today->setDate($dateArray[0], $dateArray[1], $dateArray[2] );
		$this->currentDate .= "<i>".$today->format('l')." - ".$dateArray[1]."/".$dateArray[2]."</i>";
		
		$this->schedulesData = getDaySchedule($date); //Get schedules for a specific day
		$this->scheduleStatsData = getDayScheduleStats($date);// get schedule stats for a specific day
		include_once("../views/_v_shift_changes_schedules.html");
	}	

	public function actionApproveRequest($request_id){

		if(approvePendingRequest($request_id)){
			$this->actionViewPendingRequests();
			exit;				
		} else {		
			echo "<h1> Error Approving Request</h1>";
			exit;
		}	
	}	
		
	public function actionDenyRequest($request_id){

		if(denyPendingRequest($request_id)){
			$this->actionViewPendingRequests();
			exit;				
		} else {		
			echo "<h1> Error Denying Request</h1>";
			exit;
		}	
	}	
		
}

$instancia= new shift_changes;

if(isset($_GET['view'])){
	if($_GET['view']=="list")	
		$instancia->actionViewAll();
} else if(isset($_GET['pending'])){
	if($_GET['pending']=="true")	
		$instancia->actionViewPendingRequests();
} else if(isset($_GET['date'])){
		$instancia->actionViewDaySchedule($_GET['date']);
} else if(isset($_GET['approve'])){
		$instancia->actionApproveRequest($_GET['approve']);
}else if(isset($_GET['deny'])){
		$instancia->actionDenyRequest($_GET['deny']);
} else
	$instancia->actionView();




?>